package com.studykun.client.model;

import java.util.HashSet;
import java.util.Set;

import com.google.gwt.user.client.ui.Widget;
import com.studykun.client.util.Avatar;
import com.studykun.client.util.EchoListener;
import com.studykun.client.util.EchoType;
import com.studykun.client.util.HasPresences;
import com.studykun.client.util.Presence;
import com.studykun.client.util.Room;

public abstract class AbstractAgent implements Agent, EchoListener, HasPresences {
  private Avatar avatar_;
  private Set<Presence> presences_ = new HashSet<Presence>();
  
  protected AbstractAgent(
      final Avatar avatar)
  {
    avatar_ = avatar;
  }
  
  public Avatar getAvatar() {
    return avatar_;
  }

  public void sayIn(
      final Room room,
      final String text) {
    room.echo(EchoType.NORMAL, this, text);
  }
  
  public void sayIn(
      final Room room,
      final Widget widget)
  {
    room.echo(EchoType.NORMAL, this, widget);
  }
  
  public void onAdmit(
      final Agent agent,
      final Room room)
  {
    if (agent == this) {
      // Being the agent that is admitted, we should listen to echos in the room.
      room.addEchoListener(this);
    }
  }
  
  public void onEvict(
      final Agent agent,
      final Room room)
  {
    if (agent == this) {
      // Being the agent that is admitted, we should listen to echos in the room.
      room.removeEchoListener(this);
    }
  }
  
  public void onEcho(
      final EchoType echoType,
      final Room room,
      final Agent agent,
      final String message)
  {
  }
  
  public Set<Presence> presences() {
    return presences_;
  }
}
